package game.games.carcassonne;

import game.Position;
import game.cellmap.CellMap;

import java.util.ArrayList;
import java.util.List;

public class CarcassonneMap extends CellMap
{
    private List<Tile>    tiles;
    private List<Integer> angles;
    
    public CarcassonneMap()
    {
        super(false, TileLoader.getTile(0).getBitmap().getWidth());
        tiles = new ArrayList<Tile>();
        angles = new ArrayList<Integer>();
    }
    
    public void setTile(int index, Tile tile, int angle)
    {
        tiles.set(index, tile);
        angles.set(index, angle);
    }
    
    public Tile getTile(int index)
    {
        return tiles.get(index);
    }
    
    public Integer getAngle(int index)
    {
        return angles.get(index);
    }
    
    @Override
    public void setMapSize(Position size)
    {
        // sum tiles
        int sum = size.getSum();
        while (tiles.size() > sum || angles.size() > sum)
        {
            if (tiles.size() > sum)
            {
                tiles.remove(tiles.size() - 1);
            }
            if (angles.size() > sum)
            {
                angles.remove(angles.size() - 1);
            }
        }
        while (tiles.size() < sum || angles.size() < sum)
        {
            if (tiles.size() < sum)
            {
                tiles.add(null);
            }
            if (angles.size() < sum)
            {
                angles.add(0);
            }
        }
        super.setMapSize(size);
    }
}
